package com.cytech.cloudclinic.moudle.main.clinic.admission.intelligent;

import android.content.Context;
import android.net.Uri;

import com.cytech.cloudclinic.base.BaseBean;
import com.cytech.cloudclinic.base.BaseObserver;
import com.cytech.cloudclinic.base.BasePresenter;
import com.cytech.cloudclinic.bean.Illness;
import com.cytech.cloudclinic.bean.LoadImageEntity;
import com.cytech.cloudclinic.bean.Patient;
import com.cytech.cloudclinic.bean.req.BasePage;
import com.yechaoa.yutils.ToastUtil;

import java.io.File;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class IntelligentPresenter extends BasePresenter<IntelligentView> {
    public IntelligentPresenter(IntelligentView baseView) {
        super(baseView);
    }

    /**
     * 获取疾病列表
     */
    void getIllnessList(int currentPage) {
        BasePage page = new BasePage();
        page.page = currentPage;
        addDisposable(apiServer.getIllnessList(objectToRequestBody(page)), new BaseObserver<BaseBean<List<Illness>>>(baseView, true) {

            @Override
            public void onSuccess(BaseBean<List<Illness>> o) {
                baseView.getIllnessListSuccess(o.result);
            }

            @Override
            public void onError(String msg) {
                ToastUtil.showToast(msg);
            }
        });
    }


    public void uploadImage(Context context, String filePath, Uri uri){
        //String path = GetPathFromUri.getPath(context, uri);
        File file = new File(filePath);
        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
        addDisposable(apiServer.uploadImage(filePart), new BaseObserver<BaseBean<LoadImageEntity>>(baseView,true) {
            @Override
            public void onSuccess(BaseBean<LoadImageEntity> o) {
                baseView.loadSuccess(o.result,uri);
            }

            @Override
            public void onError(String msg) {
                ToastUtil.showToast(msg);
            }
        });
    }
}
